import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },


  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },

  {
    path: '/forget-password',
    component: () => import('@/views/forget-password/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {title: '首页', icon: 'dashboard'}
    }]
  },

  {
    path: '/info',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/user-info/index'),
      meta: {title: '会员信息管理', icon: 'nested'}
    }]
  },

  {
    path: '/category',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/category/index'),
      meta: {title: '餐饮类别', icon: 'nested'}
    }]
  },

  {
    path: '/consumption',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/consumption/index'),
      meta: {title: '人均消费', icon: 'nested'}
    }]
  },

  {
    path: '/cost-performance',
    component: Layout,
    children: [{
      path: 'all',
      component: () => import('@/views/cost-performance/all'),
      meta: {title: '所有餐馆性价比', icon: 'nested'}
    }]
  },


  {
    path: '/cost-performance',
    component: Layout,
    children: [{
      path: 'type',
      component: () => import('@/views/cost-performance/type'),
      meta: {title: '餐饮类别性价比', icon: 'nested'}
    }]
  },


  {
    path: '/position',
    component: Layout,
    children: [{
      path: 'type',
      component: () => import('@/views/position/index'),
      meta: {title: '餐馆位置分布', icon: 'nested'}
    }]
  },


  // 404 page must be placed at the end !!!
  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
